/**
 * 简单工厂模式
 */
public class FactoryPattern {
    public static void main(String[] args) {
        //产品使用
        Application application = new Application();
        Product object = application.getObject("0");
        object.method();
    }
}
//抽象产品
interface Product{
    public void method();
}
//具体产品1
class ProductA implements Product{
    @Override
    public void method() {
        System.out.println("ProductA");
    }
}
//具体产品2
class ProductA1 implements  Product{
    @Override
    public void method() {
        System.out.println("ProductA1");
    }
}
//工厂类
class SimpleFactory{
    public static Product createProduct(String type){
        if (type.equals("0")){
            return new ProductA();
        }else if (type.equals("1")){
            return new ProductA1();
        }else {
            return null;
        }
    }
}
//调用具体工厂生产对应产品
class Application{
    private Product createProduct(String type){
        return SimpleFactory.createProduct(type);
    }
    Product getObject(String type){
        Product product = createProduct(type);
        return product;
    }
}